import React, { Component } from 'react'
import { Provider } from 'mobx-react'
import counterStore from './store/counter'

import './app.scss'
import Taro from "@tarojs/taro";
import {network} from "@/utils/network";


const store = {
  counterStore
}



class App extends Component {
  componentDidMount (

  ) {
    const login = async () => {
      const { code } = await Taro.login({})
      const { data: { token, user_id, partner_key } } = await network.post('/xxm/user/login', { code, userInfo: {nickName: '微信用户'} });
      Taro.setStorageSync('authorization', token)
      Taro.setStorageSync('user_id', user_id)
      Taro.setStorageSync('partner_key', partner_key)
    }
    login()
  }

  componentDidShow () {}

  componentDidHide () {}

  componentDidCatchError () {}

  // this.props.children 就是要渲染的页面
  render () {
    return (
      <Provider store={store}>
        {this.props.children}
      </Provider>
    )
  }
}

export default App
